Helper.login = {};
Helper.login.checkcode = function(id) {
	var newUrl = "";
	var oldUrl = $("#" + id).attr("src");
	if (oldUrl.indexOf("?") != -1) {
		newUrl = oldUrl.substring(0, oldUrl.indexOf("?")) + "?refresh="
				+ Math.random() * 100;
	} else {
		newUrl = oldUrl + "?refresh=" + Math.random() * 100;
	}
	$("#" + id).attr("src", newUrl);
};

Helper.login.login = function(uname,upass,vcode,success,error) {
	var remote = new Helper.RemoteTrans( {
		url : Helper.basePath + "/login.htm",
		params:{uname:uname,password:upass},
		onSuccess:function(jsonData) {
			if((!$.cookie("memberstore_member_u") || $.cookie("memberstore_member_u")!==uname) && $("#remember_pass").attr("checked")===true) {
				$.cookie("memberstore_member_u", uname, { expires: 7 });
				$.cookie("memberstore_member_p", upass, { expires: 7 });
			}else if($("#remember_pass").attr("checked")===false) {
				$.cookie("memberstore_member_u",null);
				$.cookie("memberstore_member_p",null);
			}
			
			if(typeof(success) === "function") {
				success(jsonData);
			}else {
				if(jsonData.message) {
					location.href = jsonData.message;
				}else {
					location.href = Helper.basePath + "/index.jsp";
				}
			}
		},
		onError : function(jsonData, status) {
			if(jsonData.code==="6024" && jsonData.returnObject) {
				jsonData.message = '用户名或密码错误';
				error(jsonData);
			}else {
				if(typeof(error) === "function") {
					error(jsonData);
				}
			}
		}
	});
	var url = Helper.paramsHtml("url");
	if(url) {
		remote.addParameters("url",url);
	}
	remote.send();
};

Helper.login.weixinlogin = function(uname,upass,vcode,success,error) {
	var remote = new Helper.RemoteTrans( {
		url : Helper.basePath + "/weixinlogin.htm",
		params:{loginName:uname,password:upass,url:"dtOrderQuery.htm?type="+vcode},
		onSuccess:function(jsonData) {
			if((!$.cookie("memberstore_member_u") || $.cookie("memberstore_member_u")!==uname) && $("#remember_pass").attr("checked")===true) {
				$.cookie("memberstore_member_u", uname, { expires: 7 });
				$.cookie("memberstore_member_p", upass, { expires: 7 });
			}else if($("#remember_pass").attr("checked")===false) {
				$.cookie("memberstore_member_u",null);
				$.cookie("memberstore_member_p",null);
			}
			if(typeof(success) === "function") {
				success(jsonData);
			}else {
				if(jsonData.message) {
					location.href =jsonData.message;
				}else {
					location.href = Helper.basePath + "/page/fucaidtou/error.html";
				}
			}
		},
		onError : function(jsonData, status) {
			if(jsonData.code==="6024" && jsonData.returnObject) {
				jsonData.message = '用户名或密码错误';
				error(jsonData);
			}else if(jsonData.code==="9999") {
				jsonData.message = '登录异常';
				error(jsonData);
			}else {
				if(typeof(error) === "function") {
					error(jsonData);
				}
			}
		}
	});
	var url = Helper.paramsHtml("url");
	if(url) {
		remote.addParameters("url",url);
	}
	remote.send();
};
Helper.login.validata = function(uname,upass){
	return true;
};

